package com.springboot.cloud.demos.ribbon.rest;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.springboot.cloud.common.core.entity.vo.Result;
import com.springboot.cloud.demos.entity.form.OrderForm;
import com.springboot.cloud.demos.entity.form.OrderQueryForm;
import com.springboot.cloud.demos.entity.param.OrderQueryParam;
import com.springboot.cloud.demos.entity.po.Order;
import com.springboot.cloud.demos.ribbon.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/order/conditions")
    public Result conditions(@RequestBody OrderQueryParam params) {
        return orderService.conditions(params);
    }

    @PostMapping("/order")
    public Result<Order> add(@RequestBody OrderForm orderForm) {
        return orderService.save(orderForm);
    }

    @PutMapping(value = "/order")
    public Result update(@RequestBody OrderForm order) {
        return orderService.update(order);
    }

    @GetMapping("/order/{orderId}")
    public Result<Order> get(@PathVariable(value = "orderId") String orderId) {
        return orderService.order(orderId);
    }

    @DeleteMapping("/order/{orderId}")
    public void delete(@PathVariable(value = "orderId") String orderId) {
        orderService.delete(orderId);
    }

    @PostMapping(value = "/order/page")
    public Result<Page> page(@RequestBody OrderQueryForm param) {
        return orderService.page(param);
    }

}
